package com.emspost.utils;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Validator;

import java.util.List;
import java.util.stream.Collectors;

public class PhoneUtils {

    public static void main(String[] args) {
        System.out.println(handlePhoneList(CollUtil.newArrayList("18778763917","18575035924","+8612345678910")));
    }

    public static String[] handlePhoneList(List<String> phoneList) {
        if (CollUtil.isEmpty(phoneList)) {
            return new String[0];
        }
        String[] phoneArray = new String[phoneList.size()];
        List<String> collect = phoneList.stream().map(phone -> {
            //判断phone前缀是否是 +86开头
            if (phone.startsWith("+86")) {
                String newPhone = phone.substring(3);
                if (Validator.isMobile(newPhone)) {
                    System.out.println(newPhone);
                    return phone;
                }
                return null;
            } else {
                //判断手机号
                if (Validator.isMobile(phone)) {
                    System.out.println("+86" + phone);
                    return "+86" + phone;
                }
                return null;
            }
        }).collect(Collectors.toList());

        System.out.println(collect);
        return phoneArray;

    }
}
